Fix some leaks of floating GVariants
authorSimon McVittie <smcv@debian.org>
Sat, 29 Oct 2016 17:47:11 +0000 (18:47 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Sun, 30 Oct 2016 22:11:15 +0000 (22:11 +0000)
ostree_repo_pull_with_options() and ostree_repo_remote_change() don't
sink floating GVariant arguments, and doing so now would be an
ABI change; so don't rely on them to do so.

Leak found with valgrind memcheck.

Signed-off-by: Simon McVittie <smcv@debian.org>
Closes: #556
Approved by: cgwalters

src/ostree/ot-builtin-pull.c
src/ostree/ot-remote-builtin-add.c

index 52a55375fa46f1af32c5c152e4c4390e8dbcad88..7981f18a64f8ac057a5216f618cbdf9edb9a2685 100644 (file)
@@ -208,6 +208,7 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
 
   {
     GVariantBuilder builder;
+    g_autoptr(GVariant) options = NULL;
     g_auto(GLnxConsoleRef) console = { 0, };
     g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
 
@@ -265,7 +266,9 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
                                               &console);
       }
 
-    if (!ostree_repo_pull_with_options (repo, remote, g_variant_builder_end (&builder),
+    options = g_variant_ref_sink (g_variant_builder_end (&builder));
+
+    if (!ostree_repo_pull_with_options (repo, remote, options,
                                         progress, cancellable, error))
       goto out;
 
index 6e83b2aff97ef4691470c28d5525f552e6ab4b86..9d275cb5f93153d5b9f7db591085692f909b793b 100644 (file)
@@ -50,6 +50,7 @@ ot_remote_builtin_add (int argc, char **argv, GCancellable *cancellable, GError
   const char *remote_url;
   char **iter;
   g_autoptr(GVariantBuilder) optbuilder = NULL;
+  g_autoptr(GVariant) options = NULL;
   gboolean ret = FALSE;
 
   context = g_option_context_new ("NAME [metalink=|mirrorlist=]URL [BRANCH...] - Add a remote repository");
@@ -109,11 +110,13 @@ ot_remote_builtin_add (int argc, char **argv, GCancellable *cancellable, GError
                            "gpg-verify",
                            g_variant_new_variant (g_variant_new_boolean (FALSE)));
 
+  options = g_variant_ref_sink (g_variant_builder_end (optbuilder));
+
   if (!ostree_repo_remote_change (repo, NULL,
                                   opt_if_not_exists ? OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS : 
                                   OSTREE_REPO_REMOTE_CHANGE_ADD,
                                   remote_name, remote_url,
-                                  g_variant_builder_end (optbuilder),
+                                  options,
                                   cancellable, error))
     goto out;